<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class ActivityTypeRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $createRules = [
            'name'        => 'required|unique:activity_type,name',
            'code'        => 'required|unique:activity_type,code',
            'is_roadshow' => 'required|boolean',
            'is_activity' => 'required|boolean',
        ];

        $editRules = [
            'name'        => 'required',
            'code'        => 'required',
            'status'      => 'required|boolean',
            'is_roadshow' => 'required|boolean',
            'is_activity' => 'required|boolean',
        ];
//        return array();

        $data = Request::all();
        if ($data['formType'] == 'create') {
            return $createRules;
        }

        return $editRules;
    }

    public function attributes()
    {
        $attributes = array(
            'name'        => '活动类型名',
            'status'      => '状态',
            'is_roadshow' => '是否路演',
            'is_activity' => '是否为活动'
        );

//        return array();

        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required'            => ':attribute为必填选项',
            'unique'              => ':attribute必须不能重复',
            'is_roadshow.boolean' => ':attribute必须为是路演、非路演中的一种',
            'is_activity.boolean' => ':attribute必须为是活动、不是活动中的一种',
            'status.boolean'      => ':attribute必须为可用、禁用中的一种',
        ];

        return $messages;
    }
}
